package com.ysu.zyw.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;

/**
 * EncodeUtil provide a set of operation to encode.
 * <p>
 * Created by ZeRur on 2016/1/17.
 *
 * @author yaowu.zhang
 */
public class EncodeUtil {

    /**
     * BASE64 encode
     */
    public static String base64Encode(String text) {
        Assert.hasText(text, "empty text is not allowed");
        return Base64Utils.encodeToString(text.getBytes());
    }

    /**
     * BASE64 decode
     */
    public static String base64Decode(String text) {
        Assert.hasText(text, "empty text is not allowed");
        return new String(Base64Utils.decodeFromString(text));
    }

}
